package cn.gbase.jiangsu.data.transfer.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.nutz.dao.QueryResult;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import cn.gbase.jiangsu.data.transfer.service.ProductSortTreeService;

@IocBean
@At("/sortTree")
public class ProductSortTreeAction {

	@Inject
	private ProductSortTreeService productSortTreeService;

	@At("/listTree")
	@Ok("jsp:/sortTree/listTree")
	public QueryResult list(@Param("p") int pageNumber,
			@Param("name") String name, HttpServletRequest request) {

		// 回传表单输入
		Map<String, String> itemMap = new HashMap<String, String>();
		itemMap.put("name", name);
		request.setAttribute("formdata", itemMap);

		// 查询数据
		return productSortTreeService.getStandTreeList(pageNumber, name);
	}

	/**
	 * 显示为结构图.
	 * @param treeId 树ID
	 * @param request request对象
	 */
	@At("/viewTree2")
	@Ok("jsp:/sortTree/viewTree2")
	public void toTreePage2(@Param("treeId") int treeId,HttpServletRequest request) {

		Map<String, String> itemMap = new HashMap<String, String>();
		itemMap.put("treeId", ""+treeId);
		request.setAttribute("formdata", itemMap);
		
		String json = productSortTreeService.getTreeJsonDataForECOTree(treeId);
		request.setAttribute("treedata", json);
	}
	
	/**
	 * 显示为树形图.
	 * @param treeId 树ID
	 * @param request request对象
	 */
	@At("/viewTree3")
	@Ok("jsp:/sortTree/viewTree3")
	public void toTreePage3(@Param("treeId") int treeId,HttpServletRequest request) {

		Map<String, String> itemMap = new HashMap<String, String>();
		itemMap.put("treeId", ""+treeId);
		request.setAttribute("formdata", itemMap);
		
		String json = productSortTreeService.getTreeJsonDataForZTree(treeId);
		request.setAttribute("treedata", json);
	}

}
